<?php
require_once ROOT_PATH . '/lib/models/surveys/Surveys.php';

define("YES_NO",1);
define("SELECT_ONE",2);
define("SELECT_MULTI",3);
define("ANSWER",4);

$question=null;
if(isset($records))
	$question=$records;
	$survey = Surveys::getSurvey($question['survey_id']);
	$customQuestions = Questions::getCustomQuestionsBySurvey($question['survey_id']);	
?>

<script type="text/javascript" src="../../scripts/archive.js"></script>
<?php include ROOT_PATH."/lib/common/calendar.php"; ?>
<script type="text/javascript">

function addSave() {
	if(validate()){
		document.frmQuestion.submit();
		return false;
		}
	else{
		return false;
		}
}

function showOption(){
	
	
	var value = document.getElementById('answerType').value;

	if(value==4){
		document.getElementById("txtQuestion").value="How many people answer like you?";
		document.getElementById("txtQuestion").setAttribute('readonly', 'readonly');
	}
	
	if(value==2 || value==3){
		document.getElementById("OptionValue").style.visibility="";
		document.getElementById("OptionValue").style.display="";
	}
	else{
		document.getElementById("OptionValue").style.visibility="hidden";
		document.getElementById("OptionValue").style.display="none";
	}

		
}


function validate() {
	var errFlag=false;
	var question = document.getElementById('txtQuestion').value;
	if(question.length ==0){
		alert(" Question can not be null!");
	}else{
		errFlag = true;
	}
	return errFlag;
}
/*
YAHOO.OrangeHRM.container.init();
YAHOO.util.Event.addListener($("frmReport"), "submit", viewProjectReport);
*/

</script>

<h2>
<?php echo $lang_Question_New; ?>
<hr/>
</h2>
<div id="status"></div>
<?php if (isset($_GET['message'])) {

		$expString  = $_GET['message'];
		//$col_def = CommonFunctions::getCssClassForMessage($expString);
		//$expString = 'lang_Time_Errors_' . $expString;
?>
		<font class="<?php echo $col_def?>" size="-1" face="Verdana, Arial, Helvetica, sans-serif">
<?php echo $expString; ?>
		</font>
<?php }	?>
<form name="frmQuestion" id="frmQuestion" method="post"  action="<?php echo $_SERVER['PHP_SELF']; ?>?surveycode=Surveys&action=AddQuestion">
<input type="hidden" name="surveyid" value="<?php echo $question['survey_id']; ?>">
<table border="0" cellpadding="5" cellspacing="0">
	<thead>
		<tr>
			<th class="tableTopLeft"></th>
	    	<th class="tableTopMiddle" ></th>
	    	<th class="tableTopMiddle" width="15"> </th>
	    	<th class="tableTopMiddle" width="5"></th>
	    	<th class="tableTopMiddle"></th>
			<th class="tableTopRight"></th>
		</tr>
	</thead>
	<tbody>
		
		<tr>
			<td class="tableMiddleLeft"></td>
			<td ><?php echo $lang_Question_Text; ?></td>			
			<td colspan="3">
				<TEXTAREA  id="txtQuestion" name="txtQuestion"  value="" COLS="50" ROWS="2"/></TEXTAREA>				
			</td>
			<td class="tableMiddleRight"></td>
		</tr>
		 
		<tr>
			<td class="tableMiddleLeft"></td>
			<td ><?php echo $lang_Question_Surveys; ?></td>
			<td><?php echo $survey->getSurveyName() ; ?></td>
			<!-- 
			<td >
				<select name="currentList" id="currentList" size="1" >
				<?php //foreach($surveys as $survey){
					//echo "<option value='".$survey->getId()."'>".$survey->getSurveyName()."</option>";					
				//}
				?>	
				</select>
				
			</td>
			 -->
			<td></td>
			<td></td>
			<!--  
			<td valign="center">
				<a href="#" onclick="listbox_moveacross('availableList', 'currentList')">&gt;&gt;</a>
				<br>
				<a href="#" onclick="listbox_moveacross('currentList', 'availableList')">&lt;&lt;</a>
			</td>			
			<td >
				<select name="currentList" id="currentList" size="4" multiple="multiple">
				</select>				
			</td>
			 -->
			
			<td class="tableMiddleRight"></td>
		</tr>
		 
		<tr>
			<td class="tableMiddleLeft"></td>
			<td ><?php echo $lang_Question_Type; ?></td>
			<td >
				<select name="answerType" id="answerType" size="1"  >
					<?php if($survey->getSurveyType()!=2){ ?>				
					<option value='1' >Yes/No</option>
					<?php } ?>					
					<option value='2'>Select one</option>
					<option value='3' >Select multi</option>
					<?php if($survey->getSurveyType()!=2){ ?>				
					<option value='4' >Custom answer</option>
					<?php }else if(!count($customQuestions)>0) { ?>										
					<option value='4' onclick="showOption();" >Custom answer</option>
					<?php } ?>
				</select>
				
			</td>
			<td valign="center">
			</td>			
			<td >
			</td>
			<td class="tableMiddleRight"></td>
		</tr>
						
		<tr>
			<td class="tableMiddleLeft"></td>
			
			
			
			<td >
				<input type="image"  onclick="return addSave();" name="btnSave" alt="Save"
					   src="../../themes/beyondT/pictures/btn_save.gif"
					/>
			</td>
			<td ></td>
			<td ></td>
			<td ></td>
			<td class="tableMiddleRight"></td>
		</tr>
	</tbody>
	<tfoot>
	  	<tr>
			<td class="tableBottomLeft"></td>
			<td class="tableBottomMiddle"></td>
			<td class="tableBottomMiddle"></td>
			<td class="tableBottomMiddle"></td>
			<td class="tableBottomMiddle"></td>
			<td class="tableBottomRight"></td>
		</tr>
  	</tfoot>
</table>
<div id="cal1Container" style="position:absolute;" ></div>
